﻿#include <QFile>
#include "CVideoWidgetA.h"
#include "CVideoEnlargeDlg.h"

CVideoWidgetA::CVideoWidgetA(QWidget *parent)
	: QWidget(parent)
{
	ui.setupUi(this);
	m_pDev = nullptr;
	m_bTxStart = false;
	m_bHwStart = false;
	QString sQssPath = ":/qss/styleSheet.css";
	QFile qss(sQssPath);
	qss.open(QFile::ReadOnly);
	this->setStyleSheet(qss.readAll());
	connect(ui.pushButtonVideoPlay, &QPushButton::clicked, this, &CVideoWidgetA::slotPushButtonVideoPlayClicked);
	connect(ui.pushButtonInfraredPlay, &QPushButton::clicked, this, &CVideoWidgetA::slotPushButtonInfraredPlayClicked);
	connect(ui.pushButtonVideoEnlarge, &QPushButton::clicked, this, &CVideoWidgetA::slotPushButtonInVideoEnlargeClicked);
	connect(ui.pushButtonInfraredEnlarge, &QPushButton::clicked, this, &CVideoWidgetA::slotPushButtonInfraredEnlargeClicked);
}

CVideoWidgetA::~CVideoWidgetA()
{
	if (m_bTxStart == true)
	{
		if (m_pDev)
		{
			SCtrInfo infoTx;
			infoTx.m_bCtrSync = false;
			infoTx.m_pLabel = ui.labelTxsp;
			infoTx.m_hHwnd = (HWND)ui.labelTxsp->winId();
			infoTx.m_sGuid = m_sGuid;
			infoTx.m_nCtrCmd = enCStopRealPlay;
			infoTx.m_nCtrDevType = enSubDev1;
			infoTx.m_nSubCtrDevType = enCamer;
			bool bTxRet = m_pDev->ctrDev(infoTx);
		}
	}

	if (m_bHwStart == true)
	{
		SCtrInfo infoHw;
		infoHw.m_bCtrSync = false;
		infoHw.m_pLabel = ui.labelHwsp;
		infoHw.m_hHwnd = (HWND)ui.labelHwsp->winId();
		infoHw.m_sGuid = m_sGuid;
		infoHw.m_nCtrCmd = enCStopRealPlay;
		infoHw.m_nCtrDevType = enSubDev1;
		infoHw.m_nSubCtrDevType = enIR;
		bool bHwRet = m_pDev->ctrDev(infoHw);
	}
}

void CVideoWidgetA::playVideo()
{
	if (m_pDev)
	{
		SCtrInfo infoHw;
		infoHw.m_pLabel = ui.labelHwsp;
		infoHw.m_hHwnd = (HWND)ui.labelHwsp->winId();
		infoHw.m_sGuid = m_sGuid;
		infoHw.m_nCtrCmd = enCRealPlay;
		infoHw.m_bCtrSync = false;
		infoHw.m_nCtrDevType = enSubDev1;
		infoHw.m_nSubCtrDevType = enIR;
		bool bHwRet = m_pDev->ctrDev(infoHw);
		if (bHwRet == true)
		{
			ui.pushButtonInfraredPlay->setIcon(QIcon(":/icon/Rob/PauseTask.png"));
			m_bHwStart = true;
		}

		//暂停一会儿
		QEventLoop loop;
		QTimer::singleShot(200, &loop, SLOT(quit()));
		loop.exec();
		SCtrInfo infoTx;
		infoTx.m_pLabel = ui.labelTxsp;
		infoTx.m_hHwnd = (HWND)ui.labelTxsp->winId();
		infoTx.m_sGuid = m_sGuid;
		infoTx.m_nCtrCmd = enCRealPlay;
		infoTx.m_nCtrDevType = enSubDev1;
		infoTx.m_nSubCtrDevType = enCamer;
		bool bTxRet = m_pDev->ctrDev(infoTx);
		if (bTxRet == true)
		{
			ui.pushButtonVideoPlay->setIcon(QIcon(":/icon/Rob/PauseTask.png"));
			m_bTxStart = true;
		}
	}
}

void CVideoWidgetA::slotPushButtonVideoPlayClicked()
{
	if (m_bTxStart == false)
	{
		SCtrInfo infoTx;
		infoTx.m_pLabel = ui.labelTxsp;
		infoTx.m_hHwnd = (HWND)ui.labelTxsp->winId();
		infoTx.m_sGuid = m_sGuid;
		infoTx.m_nCtrCmd = enCRealPlay;
		infoTx.m_bCtrSync = false;
		infoTx.m_nCtrDevType = enSubDev1;
		infoTx.m_nSubCtrDevType = enCamer;
		bool bTxRet = m_pDev->ctrDev(infoTx);
		if (bTxRet == true)
		{
			ui.pushButtonVideoPlay->setIcon(QIcon(":/icon/Rob/PauseTask.png"));
			m_bTxStart = true;
		}
	}
	else
	{
		SCtrInfo infoTx;
		infoTx.m_pLabel = ui.labelTxsp;
		infoTx.m_hHwnd = (HWND)ui.labelTxsp->winId();
		infoTx.m_sGuid = m_sGuid;
		infoTx.m_nCtrCmd = enCStopRealPlay;
		infoTx.m_nCtrDevType = enSubDev1;
		infoTx.m_nSubCtrDevType = enCamer;
		bool bTxRet = m_pDev->ctrDev(infoTx);
		if (bTxRet == true)
		{
			ui.pushButtonVideoPlay->setIcon(QIcon(":/icon/Rob/play.png"));
			m_bTxStart = false;
		}
	}
}

void CVideoWidgetA::slotPushButtonInfraredPlayClicked()
{
	if (m_bHwStart == false)
	{
		SCtrInfo infoHw;
		infoHw.m_pLabel = ui.labelHwsp;
		infoHw.m_hHwnd = (HWND)ui.labelHwsp->winId();
		infoHw.m_sGuid = m_sGuid;
		infoHw.m_nCtrCmd = enCRealPlay;
		infoHw.m_nCtrDevType = enSubDev1;
		infoHw.m_nSubCtrDevType = enIR;
		bool bHwRet = m_pDev->ctrDev(infoHw);
		if (bHwRet == true)
		{
			ui.pushButtonInfraredPlay->setIcon(QIcon(":/icon/Rob/PauseTask.png"));
			m_bHwStart = true;
		}
	}
	else
	{
		SCtrInfo infoHw;
		infoHw.m_pLabel = ui.labelHwsp;
		infoHw.m_hHwnd = (HWND)ui.labelHwsp->winId();
		infoHw.m_sGuid = m_sGuid;
		infoHw.m_nCtrCmd = enCStopRealPlay;
		infoHw.m_nCtrDevType = enSubDev1;
		infoHw.m_nSubCtrDevType = enIR;
		bool bHwRet = m_pDev->ctrDev(infoHw);
		if (bHwRet == true)
		{
			ui.pushButtonInfraredPlay->setIcon(QIcon(":/icon/Rob/play.png"));
			m_bHwStart = false;
		}
	}
}

void CVideoWidgetA::slotPushButtonInfraredEnlargeClicked()
{
	CVideoEnlargeDlg oper;
	oper.m_pDev = m_pDev;
	oper.m_nType = 1;
	oper.m_nCreateType = 1;
	oper.playVideoByIFDev();
	oper.exec();
}

void CVideoWidgetA::slotPushButtonInVideoEnlargeClicked()
{
	CVideoEnlargeDlg oper;
	oper.m_pDev = m_pDev;
	oper.m_nType = 0;
	oper.m_nCreateType = 1;
	oper.playVideoByIFDev();
	oper.exec();
}
